package cn.iocoder.yudao.adminserver.modules.live.dal.mysql.project;

import cn.iocoder.yudao.adminserver.modules.live.controller.project.vo.LiveProjectBaseVO;
import cn.iocoder.yudao.adminserver.modules.live.controller.project.vo.LiveProjectExportReqVO;
import cn.iocoder.yudao.adminserver.modules.live.controller.project.vo.LiveProjectPageReqVO;
import cn.iocoder.yudao.adminserver.modules.live.dal.dataobject.project.LiveProjectDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * 项目 Mapper
 *
 * @author 芋艿
 */
@Mapper
public interface LiveProjectMapper extends BaseMapperX<LiveProjectDO> {

    default PageResult<LiveProjectDO> selectPage(LiveProjectPageReqVO reqVO) {
        return selectPage(reqVO, new QueryWrapperX<LiveProjectDO>()
                .likeIfPresent("project_name", reqVO.getProjectName())
                .orderByDesc("id")        );
    }

    default List<LiveProjectDO> selectList(LiveProjectExportReqVO reqVO) {
        return selectList(new QueryWrapperX<LiveProjectDO>()
                .likeIfPresent("project_name", reqVO.getProjectName())
                .orderByDesc("id")        );
    }

    default List<LiveProjectDO> selectList(LiveProjectBaseVO liveProjectBaseVO, Collection<Long> userIds) {
        if (userIds == null) {
            userIds = Collections.emptySet();
        }
        return selectList(new QueryWrapperX<LiveProjectDO>()
                .likeIfPresent("project_name", liveProjectBaseVO.getProjectName())
                //大于等于
                .geIfPresent("project_end_date", liveProjectBaseVO.getProjectStartDate())
                //小于等于
                .leIfPresent("project_start_date", liveProjectBaseVO.getProjectEndDate())
                .inIfPresent("user_id", userIds));
    }

}
